fix(auth): parse hostname for mTLS and PSC endpoint certificate rotation (#18147) - #18201
Open
attharva-24 wants to merge 6 commits into
Open
fix(auth): parse hostname for mTLS and PSC endpoint certificate rotation (#18147)#18201attharva-24 wants to merge 6 commits into
attharva-24 wants to merge 6 commits into
Conversation
…ion (googleapis#18147) * Isolate hostname using urllib.parse.urlsplit in _mtls_helper.is_mtls_endpoint * Eliminate false positives on non-mTLS URLs containing mtls substrings in paths/queries * Add support for Private Service Connect (*.p.googleapis.com) custom mTLS endpoints * Update AuthorizedSession and AuthorizedHttp to use shared is_mtls_endpoint helper * Add comprehensive unit tests in test__mtls_helper, test_requests, and test_urllib3 Fixes googleapis#18147 Follow-up to googleapis#17928
Contributor
There was a problem hiding this comment.
Code Review
This pull request centralizes and improves mTLS and Private Service Connect (PSC) endpoint detection by introducing a robust is_mtls_endpoint helper function in _mtls_helper.py. This helper replaces redundant inline checks in both the requests and urllib3 transport implementations. Comprehensive unit tests have been added to validate the new helper across various URL formats, and existing tests have been updated to ensure proper cert rotation behavior on PSC endpoints. I have no additional feedback to provide as the changes are well-implemented and fully tested.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relands #18153 with all review feedback addressed, full test coverage, and live manual verification against Google Cloud mTLS endpoints.
Fixes #18147
Changes
any(prefix in url for prefix in MTLS_URL_PREFIXES)substring matching with_mtls_helper.is_mtls_endpoint(url).urllib.parse.urlsplitto avoid false positives on URL path/query parameters.*.p.googleapis.com,p.googleapis.com)..rstrip(".")) for FQDNs.is_mtls_endpointwithobjectinstead ofAnyfor strict static type checking.test__mtls_helper.py).Manual Verification & Findings
storage.googleapis.com): On receiving401 Unauthorized,AuthorizedSessionexecutes the standard OAuth token refresh & retry (2 HTTP requests: 401 ➔ 200 OK), and completely skips certificate rotation (spy_check Call Count: 0).storage.p.googleapis.com): On receiving401 Unauthorized,AuthorizedSessiontriggers certificate rotation inspection (spy_check Call Count: 1) before refreshing credentials and retrying with200 OK.Click to expand Live Manual Test Output (100% Green)